package Prefix_and;

import java.util.Scanner;

/**
 * Created with Intellij IDEA.
 * Description;
 * User:TQ02
 * Data:2024-01-22
 * Time:21:42
 * Text：前缀和
 */
public class Text1 {
    public static int method1() {
        Scanner sc=new Scanner(System.in);
        int size=sc.nextInt();
        int num=sc.nextInt();
        long[] array=new long[size+1];
        long[] array2=new long[size+1];
        for(int i=1;i<size+1;i++){
            array[i]=sc.nextLong();
        }
        array2[1]=array[1];
        for(int i=2;i<size+1;i++){
            array2[i]=(array[i]+array2[i-1]);
        }
        while (num>0) {
            int left = sc.nextInt();
            int right = sc.nextInt();
            System.out.println(array2[right]-array2[left-1]);
            num--;
        }
        return -1;
    }
//时间复杂度高
    public static int method(){
        Scanner sc=new Scanner(System.in);
        int size=sc.nextInt();
        int num=sc.nextInt();
        long[] array=new long[size+1];
        for(int i=1;i<size+1;i++){
            array[i]=sc.nextLong();
        }
        while (num-->0) {
            long count=0;
            int left = sc.nextInt();
            int right = sc.nextInt();
            while (left < right) {
                count+=array[left++];
                count+=array[right--];
            }
            if(left==right){
                count+=array[left];
            }
            System.out.println(count);
        }
        return -1;
    }
    public static void main(String[] args) {
    method1();
    }
}
